import 'package:flutter/cupertino.dart';

/// FileName public_tool
///
/// @Author lax
/// @Date 2023/10/10
///
/// @Description

bool stringIsEmpty(String? string) {
  return string == null || string.isEmpty;
}

bool stringIsNotEmpty(String? string) {
  return !stringIsEmpty(string);
}

int stringGetLength(String? string) {
  if (stringIsEmpty(string)) {
    return 0;
  }
  return string?.length ?? 0;
}

bool stringTrimIsEmpty(String? string) {
  return string == null || string.isEmpty || string.trim().isEmpty;
}

bool stringTrimIsNotEmpty(String? string) {
  return !stringTrimIsEmpty(string);
}

int stringTrimGetLength(String? string) {
  if (stringTrimIsEmpty(string)) {
    return 0;
  }
  return string?.trim().length ?? 0;
}

bool listIsEmpty(List? list) {
  return list == null || list.isEmpty;
}

bool listIsNotEmpty(List? list) {
  return !listIsEmpty(list);
}

int listGetLength(List? list) {
  if (listIsEmpty(list)) {
    return 0;
  }
  return list?.length ?? 0;
}

/// 判断组件是否显示
bool widgetIsVisible(Widget? widget) {
  if (widget == null) {
    return false;
  }
  if (widget is Visibility && !widget.visible) {
    final replacement = widget.replacement;
    if (replacement is SizedBox &&
        (replacement.width ?? 0) == 0 &&
        (replacement.height ?? 0) == 0 &&
        replacement.child == null) {
      return false;
    }
  }
  return true;
}
